#ifndef __DRIVER_UART_H_
#define __DRIVER_UART_H_
#include "include.h"


#define TX_FIFO_LENGTH 15
#define UART_BUFF_SIZE  128
#define UART_SEND_LENGTH 20




extern volatile u_int16 uart_rx_buff_header,uart_rx_buff_tailor;
extern volatile u_int8 uart_rx_buff[UART_BUFF_SIZE];
extern u_int8 uart_send_buff[UART_SEND_LENGTH];
extern u_int8 uart_send_length,uart_send_cnt,uart_cnt_index;


#define UART_RX_INT_DISENABLE       REG_APB3_UART_INT_ENABLE &= ~(SET_RX_FIFO_NEED_READ_EN)
#define UART_TX_INT_EN              REG_APB3_UART_INT_ENABLE |=  (SET_TX_FIFO_NEED_WRITE_EN)
#define UART_TX_INT_DISENABLE       REG_APB3_UART_INT_ENABLE &= ~(SET_TX_FIFO_NEED_WRITE_EN)
#define UART_RX_INT_EN              REG_APB3_UART_INT_ENABLE |=  (SET_RX_FIFO_NEED_READ_EN)
#define UART_TX_FIFO_COUNT          (REG_APB3_UART_FIFO_COUNT&0xff)
#define UART_RX_FIFO_COUNT          ( (REG_APB3_UART_FIFO_COUNT>>8)&0xff)


//#define PRINT_BUF_SIZE           0X0200



#define UART_WRITE_BYTE(v)               (REG_APB3_UART_DATA=v)
#define UART_READ_BYTE()                 (REG_APB3_UART_DATA&0xff)
#define UART_TX_WRITE_READY              (REG_APB3_UART_FIFO_COUNT & (0x1<<BIT_FIFO_WR_READY))
#define UART_RX_READ_READY               (REG_APB3_UART_FIFO_COUNT & (0x1<<BIT_FIFO_RD_READY))

void UART_Initial(void);


void uart_buff_send(volatile u_int8 **buf, volatile u_int32 *length);// for warning messge change
void* TRAhcit_Register_UART_Driver(void);
void uart_data_send(uint8 * buffer,uint8 len);

signed int bprintf(const char *fmt, ...);
signed int bprintf_debug(const char *fmt, ...);
void uart_callback(volatile u_int8 * buff, u_int16 len);
void UART_Interrupt_Handler(void);



#endif

